#ifndef MYSQLDATABASE_H
#define MYSQLDATABASE_H

#include "database.h"
#include <QSqlDatabase>
#include <QSqlQuery>

// MySQL数据库具体实现类
class MySQLDatabase : public Database
{
    Q_OBJECT
public:
    explicit MySQLDatabase(QObject *parent = nullptr);
    ~MySQLDatabase() override;  // 重写父类析构函数

    // 重写所有纯虚函数
    bool connect(const DatabaseConfig &config) override;
    void disconnect() override;
    bool execute(const QString &query, const QVector<QVariant> &params = QVector<QVariant>()) override;
    QVector<QMap<QString, QVariant>> query(const QString &query,
                                          const QVector<QVariant> &params = QVector<QVariant>()) override;
    bool beginTransaction() override;
    bool commitTransaction() override;
    bool rollbackTransaction() override;
    bool isConnected() const override;
    QString lastError() const override;

private:
    QSqlDatabase m_db;  // Qt MySQL连接对象
    QString m_lastError;  // 存储最后一次错误信息
};

#endif // MYSQLDATABASE_H
